//
//  ViewController.swift
//  sampleBrowser
//
//  Created by 邹佳林 on 16/7/13.
//  Copyright © 2016年 邹佳林. All rights reserved.
//

import UIKit

class ViewController: UIViewController ,UIWebViewDelegate,UITextFieldDelegate{

    @IBAction func clicked(sender: UIButton)
    {
        urlText.resignFirstResponder()
        let url = urlText.text
        loadurl(url!)
    }
    @IBOutlet weak var webView: UIWebView!
    @IBOutlet weak var btGo: UIButton!
    @IBOutlet weak var urlText: UITextField!
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        self.webView.delegate=self
        urlText.delegate=self
        }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    /*@IBAction func goClicked(sender: UIButton)
    {
        urlText.resignFirstResponder()
        let url = urlText.text
        loadurl(url!)
    }
     */
    
    func loadurl(url:String)
    {
        let urlobj = NSURL(string:url)
        let request = NSURLRequest(URL: urlobj!)
        webView.loadRequest(request)
    }
    
    func webView(webView: UIWebView, didFailLoadWithError error: NSError?)
    {
        let alertController = UIAlertController(title: "出错!",
                                                message: error!.localizedDescription,
                                                preferredStyle: UIAlertControllerStyle.Alert)
        let okAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Cancel,
                                     handler: nil)
        alertController.addAction(okAction)
        self.presentViewController(alertController, animated: true, completion: nil)
    }

}

